package com.lll.config;

import cn.hutool.setting.dialect.PropsUtil;
import com.lll.serialization.Serialization;

import java.util.Properties;

public class Config {

    private static final Properties properties;

    static {
        properties = PropsUtil.get("application.properties");
    }

    public static Serialization.Algorithm getSerializerAlgorithm() {
        String value = properties.getProperty("serialization.algorithm");
        if (value == null) {
            return Serialization.Algorithm.hession;
        } else {
            return Serialization.Algorithm.valueOf(value);
        }
    }

    public static Serialization.Algorithm getSerializerAlgorithm(int type) {
        Serialization.Algorithm[] algorithms = Serialization.Algorithm.values();
        for (Serialization.Algorithm algorithm : algorithms) {
            if (algorithm.ordinal() == type) {
                return algorithm;
            }
        }
        return Serialization.Algorithm.hession;
    }
}
